Skip to contentSkip to conversation

New: r200: Culling is broken when rendering to an FBO

Bug 57842 [email protected] 1 participant 19 messages Dec 3, 2012 – Jan 3, 2013

lore
Share & tools
lore
#0 lore raw

https://bugs.freedesktop.org/show_bug.cgi?id=57842

Priority: medium
Bug ID: 57842
Assignee: [email protected]
Summary: r200: Culling is broken when rendering to an FBO
Severity: normal
Classification: Unclassified
OS: All
Reporter: [email protected]
Hardware: Other
Status: NEW
Version: git
Component: Drivers/DRI/r200
Product: Mesa

Created attachment 70972
--> https://bugs.freedesktop.org/attachment.cgi?id=70972&action=edit
Test case

When rendering to an FBO with culling enabled, the r200 driver discards all geometry. As soon as GL_CULL_FACE is enabled, nothing is drawn. The glCullFace, glFrontFace and primitive orientation don't seem to make a difference. When rendering to a glx front or back buffer, culling behaves correctly.

The attached test case shows the issue. It creates an FBO, clears it with a blue color, and then draws a front- and back facing triangle in red and green respectively, and culls front-facing primitives. Afterwards the FBO texture is drawn to the window. The expected result is that the green triangle shows up. The actual result is a solid blue window.

I've had a quick look at the driver source code. r200FrontFace swaps front- and back facing geometry because the driver renders everything upside down on FBOs. This code doesn't seem to have any effect on this bug. What seems to trigger it is not inverting the viewport in r200UpdateWindow(), but I don't understand why.

The test case can be compiled with gcc fbo.c -o fbo -lGL -lglut , and started by simply running the binary without any parameters.

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#1 lore raw

[Bug 57842] r200: Culling is broken when rendering to an FBO

https://bugs.freedesktop.org/show_bug.cgi?id=57842

--- Comment #1 from Roland Scheidegger <[email protected]> --- Hmm this is odd I can't see anything wrong with the culling setup wrt fbos. The viewport, window handling though seems somewhat bogus.
First, r200UpdateViewportOffset() has no callers (it is used in radeon->vtbl.update_viewport_offset but that one seems to have no callers neither). This function would not take the y flip into account but since it isn't used... I'd just get rid of it but it's the only thing handling stippling that probably needs to move somewhere else.
Also, both r200UpdateViewportOffset() and r200UpdateWindow() use the driDrawable height for the yoffset in the viewport. I don't think that will work for fbos, should just use the ctx->DrawBuffer height instead? I can't see though why that would just cause failures with culling.

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw

[Bug 57842] r200: Culling is broken when rendering to an FBO

In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=57842

--- Comment #2 from Roland Scheidegger <[email protected]> --- Created attachment 71014
--> https://bugs.freedesktop.org/attachment.cgi?id=71014&action=edit
potential fixes for viewport trouble

I had something like this in mind. Untested though and all that viewport updating stuff seems really weird. I hope I didn't create circular calling chains...
Might not fix this bug at all...

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

[Bug 57842] r200: Culling is broken when rendering to an FBO

In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=57842

--- Comment #3 from Stefan Dösinger <[email protected]> --- Created attachment 71022
--> https://bugs.freedesktop.org/attachment.cgi?id=71022&action=edit
Fix for attachment 71014

The patch needed this small fix to compile. It seems that my gcc doesn't like logical operations on floats, which kinda makes sense.

Otherwise I see no difference, but I haven't really tested polygon stipple or the scissor rect on fbos yet. Clipping is still broken.

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw

[Bug 57842] r200: Culling is broken when rendering to an FBO

In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=57842

--- Comment #4 from Stefan Dösinger <[email protected]> --- (In reply to comment #3)

Quoted 1 line

Clipping is still broken.

Sorry, this should read "culling is still broken".

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw

[Bug 57842] r200: Culling is broken when rendering to an FBO

In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=57842

--- Comment #5 from smoki <[email protected]> --- Created attachment 72047
--> https://bugs.freedesktop.org/attachment.cgi?id=72047&action=edit
Myr200FrontFace

Seems like i managed to fix it, but with dirty hack... see function in
attachment. tcl somehow is not aware of wind inverting, and i just inverted commands, but it works that way :).

This fbo test case works, fbotexture and tri-cull from mesa demos - with both
swtcl and tcl. What i tested, yeah Aquaria game is no more black with fbo usage and also Supertuxkart now show icons in minimap, etc.

Anyhow, maybe someone know how to make that better to be acceptible for mesa
and pushed in git - i don't know better :).

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw

[Bug 57842] r200: Culling is broken when rendering to an FBO

In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=57842

--- Comment #6 from Stefan Dösinger <[email protected]> --- I'll give the patch a try after the holidays. My I'm currently 100 miles away from my r200-equipped laptop and won't have access to it until Wednesday or Thursday.

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#7 lore raw

[Bug 57842] r200: Culling is broken when rendering to an FBO

In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=57842

--- Comment #7 from Rafał Mużyło <[email protected]> --- Perhaps the message in this commit
(http://cgit.freedesktop.org/mesa/mesa/commit/src/mesa/drivers/dri/r200/r200_state.c?id=60e60bb3026a269fefe1cfd3312fdf3a7e4c595f)
is of note:

Tested with r300, radeon and r200 compile tested only.

Though looking at the changes of attachment 72047, perhaps the other cards should be rechecked too - these changes look more like the changes made in that commit to r300, so it might not be as much of a hack as the author thought.

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#8 lore raw

[Bug 57842] r200: Culling is broken when rendering to an FBO

In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=57842

--- Comment #8 from Rafał Mużyło <[email protected]> ---
...minor correction: that r300 was for the non-galium driver (that was removed awhile ago), but it seems that the logic in that commit was incorrect, so the "hack" from that attachement seems to be a logic fix and most likely *is* valid for radeon/radeon_state.c.

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#9 lore raw

[Bug 57842] r200: Culling is broken when rendering to an FBO

In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=57842

--- Comment #9 from smoki <[email protected]> ---

That Dänzer's commit is good, it inverts winding properly and it works good
but for swtcl only. My tries to make it work but for both swtcl and tcl, and for Stefan's test case also.

And it works for me both swtcl and tcl for those tests, but i am not very good
at programming ;).

"Fixes fgl_glxgears and progs/demos/fbotexture after pressing 'c'."

Yeah that both works too "pressing 'c'" now works. Pbuffered fgl_glxgears
works, but with -fbo switch - that never showing a texture on r200 :).

So i've tested: fgl_glxgears, fbotexture, supertuxkart, fbo test from this
bug...
and also tri-cull to be sure no-fbo case work. And that all works for swtcl and tcl on rv280.

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#10 lore raw

[Bug 57842] r200: Culling is broken when rendering to an FBO

In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=57842

--- Comment #10 from smoki <[email protected]> --- Created attachment 72050
--> https://bugs.freedesktop.org/attachment.cgi?id=72050&action=edit
STK minimap icon

He, he, i'am not programmer at all ;) but i managed to fix fogcoords, lighting
and culling on rv280 with tcl this year.

Happy holidays :).

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#11 lore raw

[Bug 57842] r200: Culling is broken when rendering to an FBO

In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=57842

smoki <[email protected]> changed:

What |Removed |Added
----------------------------------------------------------------------------

  Attachment #72050|text/plain                  |image/png
          mime type|                            |
Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#12 lore raw

[Bug 57842] r200: Culling is broken when rendering to an FBO

In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=57842

--- Comment #11 from Rafał Mużyło <[email protected]> --- Created attachment 72051
--> https://bugs.freedesktop.org/attachment.cgi?id=72051&action=edit
attachment 72047 as patch for r200/radeon

@comment 9: your own attachment says it was not.
Anyway, attachment 72047 translated into a patch.

'cull_face = (mode == GL_CW) ? R200_FFACE_CULL_CW : R200_FFACE_CULL_CCW' is bit of a mouthful, but atm. I've got not idea how to turn that into proper obfuscation style of mesa sources.

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#13 lore raw

[Bug 57842] r200: Culling is broken when rendering to an FBO

In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=57842

--- Comment #12 from smoki <[email protected]> ---

Yeah i tried your patch and it works, thanks Raphal. Someone could pushed it
in git if it's in good looking now ;).

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#14 lore raw

[Bug 57842] r200: Culling is broken when rendering to an FBO

In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=57842

--- Comment #13 from Roland Scheidegger <[email protected]> --- (In reply to comment #11)

Quoted 9 lines

Created attachment 72051 [details] [review] attachment 72047 [details] as patch for r200/radeon

@comment 9: your own attachment says it was not. Anyway, attachment 72047 [details] translated into a patch.

'cull_face = (mode == GL_CW) ? R200_FFACE_CULL_CW : R200_FFACE_CULL_CCW' is bit of a mouthful, but atm. I've got not idea how to turn that into proper obfuscation style of mesa sources.

patch looks correct to me. TCL culling is part of the tcl engine and hence ignored if there's no TCL. But viewport transform (which is where the fbo inversion happens) is done later, hence TCL culling is not subject to that inversion.
FWIW it would also be possible to simply disable TCL culling, setup culling is enough. The docs are actually saying it TCL culling is a performance optimization with questionable quality (as the coords aren't snapped to rasterizer subpixels). I guess it would also be possible to disable setup culling instead (of course only with tcl) but I'm not sure if that would make any performance compared to having enabled culling at both places.

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#15 lore raw

[Bug 57842] r200: Culling is broken when rendering to an FBO

In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=57842

--- Comment #14 from Stefan Dösinger <[email protected]> --- The patch fixes the culling issues in the dx8 d3d samples as well. Smoki, can you mail the patch to the mesa-dev list? I could do it as well, but usually it's better if the author does this.

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#16 lore raw

[Bug 57842] r200: Culling is broken when rendering to an FBO

In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=57842

--- Comment #15 from smoki <[email protected]> ---

Feel free to send it Stefan. Shame on me :( i don't know how to make proper
mesa patch nor how to send it :(.

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#17 lore raw

[Bug 57842] r200: Culling is broken when rendering to an FBO

In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=57842

--- Comment #16 from Stefan Dösinger <[email protected]> --- Commit it to Git and use git send-email to send it to [email protected] . Google finds many tutorials on how to do this.

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#18 lore raw

[Bug 57842] r200: Culling is broken when rendering to an FBO

In reply to [email protected]

https://bugs.freedesktop.org/show_bug.cgi?id=57842

Alex Deucher <[email protected]> changed:

What |Removed |Added
----------------------------------------------------------------------------

             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #17 from Alex Deucher <[email protected]> --- pushed:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=5bf357db89836d0f4e4b8a4cb559755d4734b81b

thanks!

Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel